package game;

import game.Config.Config;
import game.Config.Storage;
import game.Config.Weaponry;
import game.Menus.AdvancedMenu;

import java.awt.Font;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Vector2f;

import Weapons.Weapon;

/**
 * The GameHud shows prints valuable information to the while the game plays such as:
 * Money, Active weapon, High-score 
 * 
 * @author Sebastian Isheden and Victor Beer
 *
 */
@SuppressWarnings("deprecation") //To stop true type font warnings.
public class GameHud {
	private static Image moneyImage;
	
	private static Rectangle backgroundRectangle;
	private static TrueTypeFont trueTypeFont;
	private static float hudHeight;
	private static float hudRightOffset;
	private static float hudLeftOffset;
	private static float spacing;
	private static Color backgroundColor;
	private static Color textColor;
	private static int fps;
	
	private static AdvancedMenu weaponHud;
	
	private GameHud() { }
	
	
	/**
	 * Initializes the gamehud.
	 * @param moneyImage The image that will represent the money in the game
	 * @param font The font to gamehud will use
	 * @param hudHeight The height of the hud
	 * @param hurLeftOffset The offset the first information text will have.
	 * @param hudRightOffset The offset the last information text will have
	 * @param spacing THe spaceing between the information in the hud
	 * @param backgroundColor The color of the hud
	 * @param textColor THe text color of the hud
	 */
	public static void initialize(Image moneyImage, Font font, float hudHeight, float hurLeftOffset, float hudRightOffset, float spacing, Color backgroundColor, Color textColor) {
		GameHud.moneyImage = moneyImage;
		trueTypeFont = new TrueTypeFont(font,true);
		GameHud.hudLeftOffset = hurLeftOffset;
		GameHud.hudRightOffset = hudRightOffset;
		GameHud.spacing = spacing;
		GameHud.hudHeight = hudHeight;
		backgroundRectangle = new Rectangle(0,0, Config.SCREEN_WIDTH, hudHeight);
		GameHud.backgroundColor = backgroundColor;
		GameHud.textColor = textColor;
		
		weaponHud = new AdvancedMenu(Config.advancedMenuMarkerImage, Config.ADVANCED_MENU_MARKER_HEIGHT, Config.ADVANCED_MENU_MARKER_GAP);
		for(Weapon weapon : Weaponry.weapons) {
			weaponHud.AddItem(Weaponry.weaponImageTable.get(weapon), null);
		}
	}
	
	/**
	 * Updates the gamehud.
	 * @param gc The gamecontainer
	 * @param delta The time in millisecounds since the last update
	 */
	public static void updateHud(GameContainer gc ,int delta) {
		weaponHud.update(delta);
		
		fps = gc.getFPS();
	}
	
	/**
	 * Draws the hud
	 * @param graphic THe graphics object
	 */
	public static void drawHud(Graphics graphic) {
		graphic.setColor(backgroundColor);
		graphic.fill(backgroundRectangle);
		
		float totalLeftOffset = hudLeftOffset;
		moneyImage.draw(totalLeftOffset, hudHeight/2 - moneyImage.getHeight() / 2);
		totalLeftOffset += moneyImage.getWidth() + spacing;
		float fontHeight = trueTypeFont.getHeight();
		trueTypeFont.drawString(totalLeftOffset, hudHeight / 2 - fontHeight / 2, ""+Storage.getPlayer().getMoney(), textColor);
		graphic.setColor(Config.STANDARD_COLOR);
		
		weaponHud.draw(new Vector2f(Config.SCREEN_WIDTH / 2 - weaponHud.getWidth() / 2, hudHeight/2 - Config.ADVANCED_MENU_MARKER_HEIGHT / 2));
		
		trueTypeFont.drawString(Config.SCREEN_WIDTH - hudRightOffset, fontHeight/2, "FPS: "+ fps);
	}
	
	/**
	 * Updates the hud so it displays the right weapon as active.
	 * @param i
	 */
	public static void setActiveWeapon(int i) {
		weaponHud.setMenuIndex(i);
	}
}
